<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$this->load->view('admin/header');
$stateSelect = !empty($_GET['state']) ? $_GET['state'] : $state; 
?>
<form action="<?=site_url('admin/album/lists')?>">
	<h2>
		<select name="state">
			<option value="">全部</option>
			<option value="1" <?=$stateSelect==1?'selected':''?>>未抓取</option>
			<option value="2" <?=$stateSelect==2?'selected':''?>>已发布</option>
			<option value="5" <?=$stateSelect==5?'selected':''?>>未发布</option>
			<option value="6" <?=$stateSelect==6?'selected':''?>>抓封面</option>
			<option value="7" <?=$stateSelect==7?'selected':''?>>抓失败</option>
		</select>
		<input type="submit" value="搜索" class='abut2'/>
		<div class="operate"><a href="<?=site_url('admin/album/op')?>">添加</a></div>
	</h2>
</form>

<form action="<?=site_url('admin/album/setting')?>" method="post" class="setting">
	<table cellpadding="0" cellspacing="0" border="0" class="table2">
		<tr>
			<th width="120" style="text-align:left;padding-left:5px;">
				<select name="type">
					<option value="0">分类</option>
				<?php foreach ($type as $key => $value) { ?>
					<option value="<?=$key?>"><?=$value?></option>
				<?php } ?>
				</select>
				<input type="button" value="设置" class='abut2 submit_type'/>

				<select name="state">
					<option value="1">已发</option>
					<option value="5">未发</option>
				</select>
				<input type="button" value="设置" class='abut2 submit_state'/>
				<input type="hidden" value="type" name="action" class="action" />				
			</th>
			<th width="350">标题</th>
			<th>封面</th>
			<th width="60">分类</th>
			<th width="80">浏览量</th>
			<th width="80">状态</th>
			<th width="80">图片数</th>
			<th width="150">更新时间</th>
			<th width="50">站点</th>
			<th width="120">操作</th>
		</tr>
	<?php if($lists): foreach($lists as $v):?>
		<tr>
			<td class="ids"><input type="checkbox" name="ids[]" value="<?=$v['id']?>"></td>
			<td>
				<?=$v['title']?>
			</td>
			<td>
			<?php if($v['site'] == 3) { ?>
				<a href="<?=site_url('detail/on?aid='.$v['id'])?>" target="_blank"><img height="150" src="<?=$v['state'] == 6 ? $v['cover'] : get_thumb($v['cover'])?>"/></a>
			<?php } else { ?>
				<a href="<?=site_url('detail?aid='.$v['id'])?>" target="_blank"><img height="150" src="<?=get_thumb($v['cover'])?>"/></a>
			<?php } ?>
			</td>
			<td><?=!empty($type[$v['type']]) ? $type[$v['type']] : ''?></td>
			<td><?=$v['hits']?></td>
			<td>
			<?php 
			if($v['state'] == 0) { 
				echo "未抓取";
			} else if($v['state'] == 1) {
				echo "已发布";
			} else if($v['state'] == 5) {
				echo "未发布";
			}
			?>
			</td>
			<td><?=$v['total']?></td>		
			<td><?=$v['ctime']?></td>		
			<td><?=$v['site']?></td>		
			<td>
				<a href="<?=$v['page_url']?>" target="_blank">原地址</a>
				<? if($v['site'] == 2) { ?>
				<a href="<?=site_url('cat1/getimg?aid='.$v['id'])?>" class="catch">抓取</a>
				<? } else if($v['site'] == 3) { ?>
				<a href="<?=site_url('cat?aid='.$v['id'])?>" class="catch">抓取</a>
				<? } ?>
				<a href="<?=site_url('admin/album/op?id='.$v['id'])?>">修改</a>
				<a href="<?=site_url('admin/album/del?id='.$v['id'])?>" class="del">删除</a>
			</td>
		</tr>
	<?php endforeach; endif;?>
	</table>
</form>
<?=$pagination?>
<script type="text/javascript">
$(function() {

	$('.submit_type').click(function() {
		$('.action').val('type');
		$('.setting').submit();
	});	

	$('.submit_state').click(function() {
		$('.action').val('state');
		$('.setting').submit();
	});

	$('.del').click(function() {
		if(confirm('确认删除？')){
			var po = $(this).parent().parent();
			$.get($(this).attr('href'), '', function(data) {
				if(data == 'ok'){
					po.hide();
				} else {
					alert('删除失败！');
				}
			})
		}
		return false;
	});

	$('.catch').click(function() {
		var obj = $(this);
		obj.html('抓取...');
		$.get($(this).attr('href'), {}, function(data) {
			obj.html('完成');
		});
		return false;
	});


	$('.ids').click(function() {
		if($(this).find('input').attr('checked') == false) {
			$(this).find('input').attr('checked', true);
		} else {
			$(this).find('input').attr('checked', false);
		}
	});
})
</script>
<?php $this->load->view('admin/footer');?>